http://azinesw.hypermart.net/ (Please click the top banner)
mailto: azinenet@kagi.com
Many thanks to: Glenn R. Howes
What is AudioCDPlug 1.0?
It is a plugin for RealBasic (1.x and 2.x) that gives you control over your audio cd drive(s). This plugin has been made with the help of Glenn R. Howes' source code for AudioCDgh, a fine AppleScript OSAX for controlling AudioCD playback.
Legal mumbo-jumbo
If you want to use this plugin in any project, wether commercial, freeware, shareware, postcardware, public domain,..., you must tell me first. You don't even have to wait for a reply, you can use it for free, as long as I'm aware of it. Just so I know how popular it is.
How do I use it?
To install it you just drop it on the 'Plugins' folder in the same folder as RealBasic (you may have to create this folder first).
Here is a list of the commands and descriptions of them:
"CountAudioDrives as Integer"
This returns the number of CD-ROM drives connected to your computer. For some reason you must call this first before using the AudioCDPlug, but only once.
"GetAudioDriveRefNum (n as Integer) as Integer"
This returns the Reference Number of the n-th CD-ROM drive (0 is first). You need this number to use the other methods.
"PlayAudioCD (refnum as Integer, starttime as Integer, endtime as Integer) as Integer"
This starts playing the CD in the drive specified by 'refnum' from starttime to endtime. Starttime and endtime are relative to the beginning of the CD, not the beginning of the first track. You must know where track 1 begins. I might want to add this feature in the future, but I am not sure yet, I always use PlayAudioCDTrack. Most AudioCDs start at 768.
For more information about the time integers, read chapter 'About time'.
"PlayAudioCDTrack (refnum as Integer, track as Integer) as Integer"
This will play track number 'track' with drive 'refnum'.
"StopAudioCD (refnum as Integer) as Integer"
This will stop playing drive 'refnum'.
"GetAudioCDVolume (refnum as Integer, channel as Integer) as Integer"
This returns the level of a specified channel (channel) of a specific drive (refnum). Maximum is 255, minimum is 0.
If the result is negative, something went wrong. There are two channels 0 and 1, one for left, and one for right. But I don't know which one is left or which one is right. (Sorry)
"SetAudioCDVolume (refnum as Integer, channel as Integer, volume as Integer) as Integer"
This changes the level of a specific channel (channel) of a specific drive (refnum) to a specific value (volume). There are two channels 0 and 1, one for left, and one for right. But I don't know which one is left or which one is right. (Sorry)
"EjectCD (refnum as Integer) as Integer"
This ejects the CD in drive refnum, or opens the tray if it's empty.
"PauseAudioCD (refnum as Integer) as Integer"
This pauses playback in drive refnum.
"ResumeAudioCD (refnum as Integer) as Integer"
This resumes paused playback in drive refnum.
"GetAudioCDTrack (refnum as Integer) as Integer"
This returns the currently playing track in drive refnum.
"GetAudioCDState (refnum as Integer) as Integer"
This returns the state of drive refnum.
0 - Playing
1 - Paused
2 - Muted (?)
3 - Finished
4 - Error
5 - Stopped
Any other value is an error code.
"GetCDTrackTime (refnum as Integer) as Integer"
Returns the time since the beginning of the current track of drive refnum.
"CountCDTracks (refnum as Integer) as Integer"
This counts the number of CD tracks on the cd in drive refnum. This also counts non-audio tracks. To count only the audio-tracks, use CountAudioCDTracks.
"GetCDTotalTime (refnum as Integer) as Integer"
Returns the time since the beginning of the cd in drive refnum.
"ResumeAudioCDAt (refnum as Integer, time as Integer) as Integer"
This will make the cd in drive 'refnum' jump to a specified time.
"CountCDAudioTracks (refnum as Integer) as Integer"
This returns the number of audio tracks on the cd in drive 'refnum'. Data tracks are EXCLUDED. If you want to count data-tracks also, use CountCDTracks.
"IsAudioCDTrack (refnum as Integer, tracknumber as Integer) as Boolean"
Checks if track 'tracknumber' on the disc in drive 'refnum' is an AudioCD track.
"GetAudioCDTrackLength (refnum as Integer, tracknumber as Integer) as Integer"
Returns the length of a specified track (tracknumber) in drive (refnum). 1 is first track.
AboutTime
Time is returned as a 'long', thus 4 bytes big. The first byte has no meaning, the second one are the minutes, the third are seconds and the fourth are 'frames' (75 in one second, I believe).
Here's an example of how to convert from this value to minutes, seconds and frames:
DIM CDtime,temp,i,x as Integer
DIM houre,minute,frame as Integer
DIM refnum,drivecount as Integer
drivecount = CountAudioDrives()
refnum = GetAudioDriveRefnum(0)
CDtime = GetAudioCDTrackLength(refnum,1)
realtime = New Date
realtime.year = 1904
realtime.month = 1
realtime.day = 1
realtime.houre = 0
For i = 2 to 4
temp = CDtime
CDTime = (floor(CDtime/256))*256
x = temp - CDTime
Select case i
Case 2
minute = x
Case 3
second = x
Case 4
frame = x
Next i
msgbox "The lenght of track 1 is "+str(minute)+" minutes, "+str(second)+" seconds, and "+str(frame)+" frames."
To work the other way around, try this:
DIM CDtime as Integer
DIM minute,second,frame as Integer
CDTime = (minute * 256 + second) * 256 + frame
Error codes
I haven't figured out all error codes myself. I can give you these however:
-65532 - Data disc without audio tracks (I think)
-65530 - No disc
-50 - Invalid start/endtime.
-22 - AudioCDPlug not initialized (I think). You forgot to do a CountAudioDrives().
(They are all negative, ie below zero)
Demonstration
DIM refnum,drivecount,error,track,tt as Integer
drivecount = CountAudioDrives()
refnum = drivecount - 1 // Get the last drive
For track = 1 to CountCDAudioTracks(refnum)
If IsAudioCDTrack(refnum,track) then
exit
End if
Next
error = PlayAudioCDTrack(refnum,track)
if error <> then
beep
msgbox "An error occured. Type : "+str(error)
else
tt = ticks
while tt < ticks + 600
wend
error = PauseAudioCD(refnum)
if error <> then
beep
msgbox "An error occured. Type : "+str(error)
else
tt = ticks
while tt < ticks + 180
wend
error = ResumeAudioCD(refnum)
if error <> then
beep
msgbox "An error occured. Type : "+str(error)
else
tt = ticks
while tt < ticks + 180
wend
error = StopAudioCD(refnum)
if error <> then
beep
msgbox "An error occured. Type : "+str(error)
else
error = EjectCD(refnum)
if error <> then
beep
msgbox "An error occured. Type : "+str(error)
end if
end if
end if
end if
end if
This plays the first 10 seconds, then pauses, waits 3 seconds, resumes and plays another 3 seconds. Then it stops and ejects the disc. I hope this makes everything clear.